package com.shirley.netty.coder.server;

import com.shirley.netty.coder.decoder.MyDecoder;
import com.shirley.netty.coder.encoder.MyEncoder;
import io.netty.channel.Channel;
import io.netty.channel.ChannelInitializer;
import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
import io.netty.handler.codec.LengthFieldPrepender;
import io.netty.handler.codec.string.StringDecoder;
import io.netty.handler.codec.string.StringEncoder;
import io.netty.util.CharsetUtil;

public class CoderTcpServerChannel extends ChannelInitializer {
    @Override
    protected void initChannel(Channel ch) throws Exception {
        ch.pipeline()
                .addLast(new LengthFieldPrepender(4))
                .addLast(new StringEncoder(CharsetUtil.UTF_8))
                .addLast(new MyEncoder())

                .addLast(new LengthFieldBasedFrameDecoder(1024, 0, 4, 0, 4))
                .addLast(new StringDecoder())
                .addLast(new MyDecoder())
                .addLast(new CoderTcpServerInputMsgHandler());

    }
}
